package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSourceConfig;
import com.ruoyi.system.service.ISysSourceConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据源配置Controller
 * 
 * @author ruoyi
 * @date 2022-04-21
 */
@RestController
@RequestMapping("/system/sys_source_config")
public class SysSourceConfigController extends BaseController
{
    @Autowired
    private ISysSourceConfigService sysSourceConfigService;

    /**
     * 查询数据源配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:sys_source_config:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSourceConfig sysSourceConfig)
    {
        startPage();
        List<SysSourceConfig> list = sysSourceConfigService.selectSysSourceConfigList(sysSourceConfig);
        return getDataTable(list);
    }

    /**
     * 导出数据源配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:sys_source_config:export')")
    @Log(title = "数据源配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysSourceConfig sysSourceConfig)
    {
        List<SysSourceConfig> list = sysSourceConfigService.selectSysSourceConfigList(sysSourceConfig);
        ExcelUtil<SysSourceConfig> util = new ExcelUtil<SysSourceConfig>(SysSourceConfig.class);
        return util.exportExcel(list, "sys_source_config");
    }

    /**
     * 获取数据源配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sys_source_config:query')")
    @GetMapping(value = "/{sourceId}")
    public AjaxResult getInfo(@PathVariable("sourceId") Long sourceId)
    {
        return AjaxResult.success(sysSourceConfigService.selectSysSourceConfigById(sourceId));
    }

    /**
     * 新增数据源配置
     */
    @PreAuthorize("@ss.hasPermi('system:sys_source_config:add')")
    @Log(title = "数据源配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSourceConfig sysSourceConfig)
    {
        return toAjax(sysSourceConfigService.insertSysSourceConfig(sysSourceConfig));
    }

    /**
     * 修改数据源配置
     */
    @PreAuthorize("@ss.hasPermi('system:sys_source_config:edit')")
    @Log(title = "数据源配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSourceConfig sysSourceConfig)
    {
        return toAjax(sysSourceConfigService.updateSysSourceConfig(sysSourceConfig));
    }

    /**
     * 删除数据源配置
     */
    @PreAuthorize("@ss.hasPermi('system:sys_source_config:remove')")
    @Log(title = "数据源配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sourceIds}")
    public AjaxResult remove(@PathVariable Long[] sourceIds)
    {
        return toAjax(sysSourceConfigService.deleteSysSourceConfigByIds(sourceIds));
    }
}
